# # 给函数添加时间统计功能
# import time
#
#
# def index():
#     time.sleep(2)
#     print('from index')
#
#
# def home():
#     time.sleep(2)
#     print('from home')
#
#
# def outer(func):
#     def get_time():
#         # 开始时间
#         start_time = time.time()
#         # 执行函数
#         func()
#         # 结束时间
#         end_time = time.time()
#         # 打印时间
#         print("函数执行时间为 %s 秒" % (end_time - start_time))
#
#     return get_time
#
#
# # 利用闭包的形式传参
# index = outer(index)  # res_index  == outer(index)  == get_time
# index()
# home = outer(home)
# home()


# 给函数添加时间统计功能
import time


def index(a):
    time.sleep(2)
    print('from index')
    return 123




def outer(func):
    def get_time(*args,**kwargs):
        print("执行后添加的额外功能")
        res=func(*args,**kwargs)  # home() == 'abc'
        print("执行后添加的额外功能")
        return res
    return get_time


index = outer(index)  # res_index  == outer(index)  == get_time
print(index())

# ()调用，调用优先级最高

